<template>
	<view class="container" v-if="!loading">
		<view class="main" v-if="goods.length">
			<template v-for="(item, index) in globalState.indexImgs" :key="index">
				<image class="banner" mode="aspectFill" :src="item.url" v-if="item.code == 1001" />
			</template>

			<view class="content">
				<scroll-view class="menus" :scroll-into-view="menuScrollIntoView" scroll-with-animation scroll-y>
					<view class="wrapper">
						<view
							class="menu"
							:id="`menu-${item.id}`"
							:class="{ current: item.id === currentCateId }"
							v-for="(item, index) in goods"
							:key="index"
							@tap="handleMenuTap(item.id)"
						>
							<text>{{ item.title }}</text>
							<view class="dot" v-show="menuCartNum(item.id)">{{ menuCartNum(item.id) }}</view>
						</view>
					</view>
				</scroll-view>
				<!-- goods list begin -->
				<scroll-view class="goods" scroll-with-animation scroll-y :scroll-top="cateScrollTop" @scroll="handleGoodsScroll">
					<view class="wrapper">
						<swiper class="ads" id="ads" autoplay :interval="3000" indicator-dots>
							<template v-for="(item, index) in globalState.indexImgs" :key="index">
								<swiper-item v-if="item.code == 1002">
									<image :src="item.url"></image>
								</swiper-item>
							</template>
						</swiper>
						<view class="list">
							<!-- category begin -->
							<view class="category" v-for="(item, index) in goods" :key="index" :id="`cate-${item.id}`">
								<view class="title">
									<text>{{ item.title }}</text>
									<image :src="item.icon" class="icon"></image>
								</view>
								<view class="items">
									<!-- 商品 begin -->
									<view class="good" v-for="(good, key) in item.goods_list" :key="key">
										<image :src="good.img" class="image" @tap="showGoodDetailModal(item, good)"></image>
										<view class="right">
											<text class="name">{{ good.title }}</text>
											<text class="tips">{{ good.des }}</text>
											<view class="price_and_action">
												<text class="price">￥{{ good.price }}</text>
												<view class="btn-group">
													<button
														type="default"
														v-show="goodCartNum(good.id)"
														plain
														class="btn reduce_btn"
														size="mini"
														hover-class="none"
														@tap="handleReduceFromCart(item, good)"
													>
														<view class="iconfont iconsami-select"></view>
													</button>
													<view class="number" v-show="goodCartNum(good.id)">{{ goodCartNum(good.id) }}</view>
													<button type="primary" class="btn add_btn" size="min" hover-class="none" @tap="handleAddToCart(item, good, 1)">
														<view class="iconfont iconadd-select"></view>
													</button>
												</view>
											</view>
										</view>
									</view>
									<!-- 商品 end -->
								</view>
							</view>
							<!-- category end -->
						</view>
					</view>
				</scroll-view>
				<!-- goods list end -->
			</view>
			<!-- content end -->
			<!-- 购物车栏 begin -->
			<view class="cart-box" v-if="cart.length > 0">
				<view class="mark">
					<image src="/static/images/menu/cart.png" class="cart-img" @tap="openCartPopup"></image>
					<view class="tag">{{ getCartGoodsNumber }}</view>
				</view>
				<view class="price">￥{{ getCartGoodsPrice }}</view>
				<button type="primary" class="pay-btn" @tap="toPay" :disabled="disabledPay">
					{{ disabledPay ? `差${spread}元起送` : '去结算' }}
				</button>
			</view>
			<!-- 购物车栏 end -->
		</view>
		<!-- 商品详情模态框 begin -->

		<modal :show="goodDetailModalVisible" class="good-detail-modal" color="#5A5B5C" width="90%" custom padding="0rpx" radius="12rpx">
			<view class="cover">
				<image v-if="good.img" :src="good.img" class="image"></image>
				<view class="btn-group">
					<image src="/static/images/menu/share-good.png"></image>
					<image src="/static/images/menu/close.png" @tap="closeGoodDetailModal"></image>
				</view>
			</view>
			<scroll-view class="detail" scroll-y>
				<view class="wrapper">
					<view class="basic">
						<view class="name">{{ good.title }}</view>
						<view class="tips">{{ good.des }}</view>
					</view>
				</view>
			</scroll-view>
			<view class="action">
				<view class="left">
					<view class="price">￥{{ good.price }}</view>
				</view>
				<view class="btn-group">
					<button type="default" plain class="btn" size="mini" hover-class="none" @tap="handlePropertyReduce">
						<view class="iconfont iconsami-select"></view>
					</button>
					<view class="number">{{ good.number }}</view>
					<button type="primary" class="btn" size="min" hover-class="none" @tap="handlePropertyAdd">
						<view class="iconfont iconadd-select"></view>
					</button>
				</view>
			</view>
			<view class="add-to-cart-btn" @tap="handleAddToCartInModal">
				<view>加入购物车</view>
			</view>
		</modal>
		<!-- 商品详情模态框 end -->
		<!-- 购物车详情popup -->
		<popup-layer v-show="cartPopupVisible" :autoClose="false" :show-pop="cartPopupVisible" direction="top" class="cart-popup">
			<template #content>
				<view class="top">
					<text @tap="handleCartClear">清空</text>
				</view>
				<scroll-view class="cart-list" scroll-y>
					<view class="wrapper">
						<view class="item" v-for="(item, index) in cart" :key="index">
							<view class="left">
								<view class="name">{{ item.title }}</view>
							</view>
							<view class="center">
								<text>￥{{ item.price }}</text>
							</view>
							<view class="right">
								<button type="default" plain size="mini" class="btn" hover-class="none" @tap="handleCartItemReduce(index)">
									<view class="iconfont iconsami-select"></view>
								</button>
								<view class="number">{{ item.number }}</view>
								<button type="primary" class="btn" size="min" hover-class="none" @tap="handleCartItemAdd(index)">
									<view class="iconfont iconadd-select"></view>
								</button>
							</view>
						</view>
					</view>
				</scroll-view>
			</template>
		</popup-layer>
		<!-- 购物车详情popup -->
	</view>
	<loadingModel v-else />
</template>

<script lang="ts" setup>
import { ref, computed, nextTick } from 'vue';
import modal from '../components/modal.vue';
import popupLayer from '../components/popup-layer.vue';
import { onLoad, onShow, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
import { state, getCart } from '../../store/shop';
import { ROLE_MER, state as userState, setPId, getPId } from '../../store/user';
import { setCart, setEmptyCart } from '../../store/shop';
import getUser from '../../vendor/user';
import getAd from '../../vendor/ads';
import getCategory from '../../vendor/order_food/category';
import getGoods from '../../vendor/order_food/goods';
import getOrders from '../../vendor/order_food/order';
import { initSocket, state as socketState } from '../../store/imStore';
import { state as globalState } from '@/store/global';
import { state as systemState } from '../../store/system';
import http from '../../vendor/http';
import loadingModel from '@/pages/components/loading.vue';
import getShop from '@/vendor/shop/shop';

const { get } = getShop();

const { getList, getBusList } = getOrders();
const { login } = getUser();

const { getAds } = getAd();
const { category } = getCategory();

const { list: goodsList, getUserGoodsList: getGoodsList, goods: good, goodsInit } = getGoods();

const goods = ref<any>(goodsList); //所有商品
const loading = ref(true);
const currentCateId = ref(0); //默认分类
const cateScrollTop = ref(0);
const menuScrollIntoView = ref('');
// const cart = ref(JSON.parse(JSON.stringify(getCart()))); //购物车
const cart = getCart(); //购物车
const goodDetailModalVisible = ref(false); //是否饮品详情模态框
const cartPopupVisible = ref(false);
const sizeCalcState = ref(false);

onLoad(({ id }) => {
	//  #ifdef  MP-WEIXIN
	if (id == undefined) {
		// 用户刷新
		id = getPId();
		if (id == undefined || !id) {
			// 用户搜索
			id = 1;
		}
	}
	console.log(id);

	uni.login({
		success: (res: any) => {
			login(id, res.code, (res) => {
				init();
			});
		}
	});

	// #endif

	// #ifdef H5
	init();
	// #endif
});

const goodCartNum = computed(() => {
	return (id) =>
		cart.reduce((acc, cur) => {
			if (cur.id === id) {
				return (acc += cur.number);
			}
			return acc;
		}, 0);
});

const menuCartNum = computed(() => {
	return (id) =>
		cart.reduce((acc, cur) => {
			if (cur.cate_id === id) {
				return (acc += cur.number);
			}
			return acc;
		}, 0);
});

const getCartGoodsNumber = computed(() => {
	//计算购物车总数
	return cart.reduce((acc, cur) => acc + cur.number, 0);
});

const getCartGoodsPrice = computed(() => {
	//计算购物车总价
	const v = cart.reduce((acc, cur) => acc + cur.number * cur.price, 0);

	return v.toFixed(2);
});

const spread = computed(() => {
	//差多少元起送

	return parseFloat((Number(state.shop.min_price) - Number(getCartGoodsPrice.value)).toFixed(2));
});

const disabledPay = computed(() => {
	//是否达到起送价
	return Number(getCartGoodsPrice.value) < Number(state.shop.min_price) ? true : false;
});

const init = () => {
	// 广告
	getAds(userState.p_id, () => {});

	// 商品列表
	getGoodsList(userState.p_id, () => {
		if (goodsList.value.length) {
			currentCateId.value = goodsList.value[0].id;
		}
		loading.value = false;
	});

	http.fetchGet('/sysInfo').then((res: any) => {
		systemState.fee_rate = res.fee_rate;
		systemState.hide_mer = res.hide_mer;
	});

	// 获取系统消息
	// 绑定socket
	initSocket(() => {});

	getBusList(() => {});


	getList(() => {});

	// 获取系统消息
	// pid 商铺信息
	get(() => {});

	const pid = userState.store_phone ? userState.id : userState.p_id;
	// 设置分享
	onShareAppMessage(() => {
		return {
			title: '我要给你安利一个买水果蔬菜神器', // 分享标题
			path: `/pages/tabbar/index?id=${pid}`, // 默认为当前页面路径
			imageUrl: '' // 默认为当前页面的截图
		};
	});
	onShareTimeline(() => {
		return {
			title: '我要给你安利一个买水果蔬菜神器', // 分享标题
			path: `/pages/tabbar/index?id=${pid}`, // 默认为当前页面路径
			imageUrl: '' // 默认为当前页面的截图
		};
	});
};

const handleMenuTap = (id) => {
	if (!sizeCalcState.value) {
		calcSize();
	}
	currentCateId.value = id;
	nextTick(() => {
		cateScrollTop.value = goods.value.find((item) => item.id == id).top;
	});
};

const handleGoodsScroll = ({ detail }) => {
	if (!sizeCalcState.value) {
		calcSize();
	}
	const { scrollTop } = detail;
	let tabs = goods.value.filter((item) => item.top <= scrollTop + 3).reverse();
	if (tabs.length > 0) {
		currentCateId.value = tabs[0].id;
	}
};

function calcSize() {
	let h = 10;
	let view = uni.createSelectorQuery().select('#ads');
	view.fields(
		{
			size: true
		},
		(data: any) => {
			h += Math.floor(data.height);
		}
	).exec();
	goods.value.forEach((item) => {
		let view = uni.createSelectorQuery().select(`#cate-${item.id}`);
		view.fields(
			{
				size: true
			},
			(data: any) => {
				item.top = h;
				h += data.height;
				item.bottom = h;
			}
		).exec();
	});
	sizeCalcState.value = true;
}
function handleAddToCart(cate, good, num) {
	if (good.stock == 0) {
		uni.showToast({
			title: '当前商品库存不足~',
			icon: 'none'
		});
		return;
	}

	//添加到购物车
	const index = cart.findIndex((item) => {
		return item.id === good.id;
	});
	if (index > -1) {
		cart[index].number += num;
		console.log(cart[index]);
		// setCart({
		// 	id: good.id,
		// 	title: good.title,
		// 	price: good.price,
		// 	number: cart[index].number,
		// 	img: good.img,
		// 	cate_id: cate.id
		// });
		setCart();
	} else {
		cart.push({
			id: good.id,
			title: good.title,
			price: good.price,
			number: num,
			img: good.img,
			cate_id: cate.id
		});
		setCart();
		// setCart({
		// 	id: good.id,
		// 	title: good.title,
		// 	price: good.price,
		// 	number: num,
		// 	img: good.img,
		// 	cate_id: cate.id
		// });
	}
}
function handleReduceFromCart(item, good) {
	const index = cart.findIndex((item) => item.id === good.id);
	cart[index].number -= 1;
	if (cart[index].number <= 0) {
		cart.splice(index, 1);
	}
}
function showGoodDetailModal(item, g) {
	good.value = JSON.parse(JSON.stringify({ ...g, number: 1 }));

	category.value = JSON.parse(JSON.stringify(item));
	goodDetailModalVisible.value = true;
}
function closeGoodDetailModal() {
	//关闭饮品详情模态框
	goodDetailModalVisible.value = false;
	category.value.id = 0;
	category.value.title = '';
	category.value.sort = 0;
	good.value = goodsInit;
}

function handlePropertyAdd() {
	good.value.number += 1;
}
function handlePropertyReduce() {
	if (good.value.number === 1) return;
	good.value.number -= 1;
}
function handleAddToCartInModal() {
	const product = Object.assign({}, good.value);
	handleAddToCart(category.value, product, good.value.number);
	closeGoodDetailModal();
}
function openCartPopup() {
	//打开/关闭购物车列表popup
	cartPopupVisible.value = !cartPopupVisible.value;
}
function handleCartClear() {
	//清空购物车
	uni.showModal({
		title: '提示',
		content: '确定清空购物车么',
		success: ({ confirm }) => {
			if (confirm) {
				cartPopupVisible.value = false;
				cart.length = 0;
				setEmptyCart();
			}
		}
	});
}
function handleCartItemAdd(index) {
	cart[index].number += 1;
}
function handleCartItemReduce(index) {
	if (cart[index].number === 1) {
		cart.splice(index, 1);
	} else {
		cart[index].number -= 1;
	}
	if (!cart.length) {
		cartPopupVisible.value = false;
	}
}
function toPay() {
	uni.navigateTo({
		url: '/pages/user/pay'
	});
}
</script>

<style lang="scss" scoped>
@import '@/styles/order_food.scss';
/* #ifdef H5 */
page {
	min-height: 100%;
}
/* #endif */

.container {
	overflow: hidden;
	position: relative;
}

.banner {
	width: 100%;
	height: 120px;
}

.loading {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;

	image {
		width: 260rpx;
		height: 260rpx;
		position: relative;
		margin-top: -200rpx;
		/* #ifdef h5 */
		margin-top: 0;
		/* #endif */
	}
}

.stores {
	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	margin-bottom: -40rpx;
	.store {
		width: 100%;
		background-color: $bg-color-grey;
		padding: 20rpx;
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
		border-radius: 6rpx;

		.iconfont {
			font-size: 50rpx;
			margin-right: 15rpx;

			&.iconradio-button-off {
				color: $text-color-assist;
			}

			&.iconradio-button-on {
				color: $color-primary;
			}
		}

		.infos {
			flex: 1;
			display: flex;
			flex-direction: column;
			color: $text-color-base;
			overflow: hidden;

			.name_and_distance {
				width: 100%;
				display: flex;
				justify-content: space-between;
				margin-bottom: 10rpx;
				overflow: hidden;

				.name {
					flex: 1;
					flex-shrink: 0;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: $font-size-lg;
				}

				.distance {
					flex-shrink: 0;
					font-size: $font-size-lg;
					font-weight: bold;
					margin-left: 20rpx;
				}
			}

			.street {
				color: $text-color-assist;
				font-size: $font-size-sm;
			}
		}
	}
}

.main {
	width: 100%;
	height: 100%;
	position: relative;
	display: flex;
	flex-direction: column;
}

.nav {
	width: 100%;
	height: 212rpx;
	flex-shrink: 0;
	display: flex;
	flex-direction: column;

	.header {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		background-color: #ffffff;
		height: 140rpx;

		.left {
			flex: 1;
			display: flex;
			flex-direction: column;

			.store-name {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				font-size: $font-size-lg;
				margin-bottom: 10rpx;

				.iconfont {
					margin-left: 10rpx;
					line-height: 100%;
				}
			}

			.store-location {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				color: $text-color-assist;
				font-size: $font-size-sm;

				.iconfont {
					vertical-align: middle;
					display: table-cell;
					color: $color-primary;
					line-height: 100%;
				}
			}
		}

		.right {
			background-color: $bg-color-grey;
			border-radius: 38rpx;
			display: flex;
			align-items: center;
			font-size: $font-size-sm;
			padding: 0 38rpx;
			color: $text-color-assist;

			.dinein,
			.takeout {
				position: relative;
				display: flex;
				align-items: center;
				&.active {
					padding: 14rpx 38rpx;
					color: #ffffff;
					background-color: $color-primary;
					border-radius: 38rpx;
				}
			}

			.takeout {
				margin-left: 20rpx;
				height: 100%;
				flex: 1;
				padding: 14rpx 0;
			}

			.dinein.active {
				margin-left: -38rpx;
			}

			.takeout.active {
				margin-right: -38rpx;
			}
		}
	}

	.coupon {
		flex: 1;
		width: 100%;
		background-color: $bg-color-primary;
		font-size: $font-size-base;
		color: $color-primary;
		padding: 0 20rpx;
		display: flex;
		align-items: center;
		overflow: hidden;

		.title {
			flex: 1;
			margin-left: 10rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.iconfont {
			line-height: 100%;
		}
	}
}

.content {
	flex: 1;
	overflow: hidden;
	width: 100%;
	display: flex;

	.menus {
		width: 200rpx;
		height: 100%;
		overflow: hidden;
		background-color: $bg-color-grey;

		.wrapper {
			width: 100%;
			height: 100%;

			.menu {
				display: flex;
				align-items: center;
				justify-content: flex-start;
				padding: 30rpx 20rpx;
				font-size: 26rpx;
				color: $text-color-assist;
				position: relative;

				&:nth-last-child(1) {
					margin-bottom: 130rpx;
				}

				&.current {
					background-color: #ffffff;
					color: $text-color-base;
				}

				.dot {
					position: absolute;
					width: 34rpx;
					height: 34rpx;
					line-height: 34rpx;
					font-size: 22rpx;
					background-color: $color-primary;
					color: #ffffff;
					top: 16rpx;
					right: 10rpx;
					border-radius: 100%;
					text-align: center;
				}
			}
		}
	}

	.goods {
		flex: 1;
		height: 100%;
		overflow: hidden;
		background-color: #ffffff;

		.wrapper {
			width: 100%;
			height: 100%;
			padding: 20rpx;

			.ads {
				height: calc(300 / 550 * 510rpx);

				image {
					width: 100%;
					height: 100%;
					border-radius: 8rpx;
				}
			}

			.list {
				width: 100%;
				font-size: $font-size-base;
				padding-bottom: 130rpx;

				.category {
					width: 100%;

					.title {
						padding: 30rpx 0;
						display: flex;
						align-items: center;
						color: $text-color-base;

						.icon {
							width: 38rpx;
							height: 38rpx;
							margin-left: 10rpx;
						}
					}
				}

				.items {
					display: flex;
					flex-direction: column;
					padding-bottom: -30rpx;

					.good {
						display: flex;
						align-items: center;
						margin-bottom: 30rpx;

						.image {
							width: 160rpx;
							height: 160rpx;
							margin-right: 20rpx;
							border-radius: 8rpx;
						}

						.right {
							flex: 1;
							height: 160rpx;
							overflow: hidden;
							display: flex;
							flex-direction: column;
							align-items: flex-start;
							justify-content: space-between;
							padding-right: 14rpx;

							.name {
								font-size: $font-size-base;
								margin-bottom: 10rpx;
							}

							.tips {
								width: 100%;
								height: 40rpx;
								line-height: 40rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
								font-size: $font-size-sm;
								color: $text-color-assist;
								margin-bottom: 10rpx;
							}

							.price_and_action {
								width: 100%;
								display: flex;
								justify-content: space-between;
								align-items: center;

								.price {
									font-size: $font-size-base;
									font-weight: 600;
								}

								.btn-group {
									display: flex;
									justify-content: space-between;
									align-items: center;
									position: relative;

									.btn {
										padding: 0 20rpx;
										box-sizing: border-box;
										font-size: $font-size-sm;
										height: 44rpx;
										line-height: 44rpx;

										&.property_btn {
											border-radius: 24rpx;
										}

										&.add_btn,
										&.reduce_btn {
											padding: 0;
											width: 44rpx;
											border-radius: 44rpx;
										}
									}

									.dot {
										position: absolute;
										background-color: #ffffff;
										border: 1px solid $color-primary;
										color: $color-primary;
										font-size: $font-size-sm;
										width: 36rpx;
										height: 36rpx;
										line-height: 36rpx;
										text-align: center;
										border-radius: 100%;
										right: -12rpx;
										top: -10rpx;
									}

									.number {
										width: 44rpx;
										height: 44rpx;
										line-height: 44rpx;
										text-align: center;
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

.modal-box {
	max-height: 90vh;
}

.good-detail-modal {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;

	.cover {
		height: 320rpx;
		padding: 30rpx 0;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;

		.image {
			width: 260rpx;
			height: 260rpx;
		}

		.btn-group {
			position: absolute;
			right: 10rpx;
			top: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;

			image {
				width: 80rpx;
				height: 80rpx;
			}
		}
	}

	.detail {
		width: 100%;
		min-height: 1vh;
		max-height: calc(90vh - 320rpx - 80rpx - 120rpx);

		.wrapper {
			width: 100%;
			height: 100%;
			overflow: hidden;

			.basic {
				padding: 0 20rpx 30rpx;
				display: flex;
				flex-direction: column;
				.name {
					font-size: $font-size-base;
					color: $text-color-base;
					margin-bottom: 10rpx;
				}
				.tips {
					font-size: $font-size-sm;
					color: $text-color-grey;
				}
			}

			.properties {
				width: 100%;
				border-top: 2rpx solid $bg-color-grey;
				padding: 10rpx 30rpx 0;
				display: flex;
				flex-direction: column;

				.property {
					width: 100%;
					display: flex;
					flex-direction: column;
					margin-bottom: 30rpx;
					padding-bottom: -16rpx;

					.title {
						width: 100%;
						display: flex;
						justify-content: flex-start;
						align-items: center;
						margin-bottom: 20rpx;

						.name {
							font-size: 26rpx;
							color: $text-color-base;
							margin-right: 20rpx;
						}

						.desc {
							flex: 1;
							font-size: $font-size-sm;
							color: $color-primary;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}

					.values {
						width: 100%;
						display: flex;
						flex-wrap: wrap;

						.value {
							border-radius: 8rpx;
							background-color: $bg-color-grey;
							padding: 16rpx 30rpx;
							font-size: 26rpx;
							color: $text-color-assist;
							margin-right: 16rpx;
							margin-bottom: 16rpx;

							&.default {
								background-color: $color-primary;
								color: $text-color-white;
							}
						}
					}
				}
			}
		}
	}

	.action {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: $bg-color-grey;
		height: 120rpx;
		padding: 0 26rpx;

		.left {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;
			margin-right: 20rpx;
			overflow: hidden;

			.price {
				font-size: $font-size-lg;
				color: $text-color-base;
			}

			.props {
				color: $text-color-assist;
				font-size: 24rpx;
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}
		.btn-group {
			display: flex;
			align-items: center;
			justify-content: space-around;

			.number {
				font-size: $font-size-base;
				width: 44rpx;
				height: 44rpx;
				line-height: 44rpx;
				text-align: center;
			}

			.btn {
				padding: 0;
				font-size: $font-size-base;
				width: 44rpx;
				height: 44rpx;
				line-height: 44rpx;
				border-radius: 100%;
			}
		}
	}

	.add-to-cart-btn {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: $color-primary;
		color: $text-color-white;
		font-size: $font-size-base;
		height: 80rpx;
		border-radius: 0 0 12rpx 12rpx;
	}
}

.cart-box {
	position: absolute;
	bottom: 30rpx;
	left: 30rpx;
	right: 30rpx;
	height: 96rpx;
	border-radius: 48rpx;
	box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.2);
	background-color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	z-index: 9999;

	.cart-img {
		width: 96rpx;
		height: 96rpx;
		position: relative;
		margin-top: -48rpx;
	}

	.pay-btn {
		height: 100%;
		padding: 0 30rpx;
		color: #ffffff;
		border-radius: 0 50rpx 50rpx 0;
		display: flex;
		align-items: center;
		font-size: $font-size-base;
	}

	.mark {
		padding-left: 46rpx;
		margin-right: 30rpx;
		position: relative;

		.tag {
			background-color: $color-warning;
			color: $text-color-white;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: $font-size-sm;
			position: absolute;
			right: -10rpx;
			top: -50rpx;
			border-radius: 100%;
			padding: 4rpx;
			width: 40rpx;
			height: 40rpx;
			opacity: 0.9;
		}
	}

	.price {
		flex: 1;
		color: $text-color-base;
	}
}

.cart-popup {
	transition: all 0.3s ease;
	.top {
		background-color: $bg-color-primary;
		color: $color-primary;
		padding: 10rpx 30rpx;
		font-size: 24rpx;
		text-align: right;
	}
	.cart-list {
		background-color: #ffffff;
		width: 100%;
		overflow: hidden;
		min-height: 1vh;
		max-height: 60vh;

		.wrapper {
			height: 100%;
			display: flex;
			flex-direction: column;
			padding: 0 30rpx;
			margin-bottom: 156rpx;

			.item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 0;
				position: relative;

				&::after {
					content: ' ';
					position: absolute;
					bottom: 0;
					left: 0;
					width: 100%;
					background-color: $border-color;
					height: 2rpx;
					transform: scaleY(0.6);
				}

				.left {
					flex: 1;
					display: flex;
					flex-direction: column;
					overflow: hidden;
					margin-right: 30rpx;

					.name {
						font-size: $font-size-sm;
						color: $text-color-base;
					}
					.props {
						color: $text-color-assist;
						font-size: 24rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}

				.center {
					margin-right: 120rpx;
					font-size: $font-size-base;
				}

				.right {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.btn {
						width: 46rpx;
						height: 46rpx;
						border-radius: 100%;
						padding: 0;
						text-align: center;
						line-height: 46rpx;
					}

					.number {
						font-size: $font-size-base;
						width: 46rpx;
						height: 46rpx;
						text-align: center;
						line-height: 46rpx;
					}
				}
			}
		}
	}
}
</style>
